#!/usr/bin/env python
#encoding=UTF-8

from ObjectFactory import *

def GetTimeNeed(building, from_level, to_level):
	if from_level >= to_level:
		return 0
	time_need = 0
	for l in range(from_level+1, to_level+1):
		time_need += building.GetBuildTime(l)
	return time_need

def GetCost(building, from_level, to_level):
	if from_level >= to_level:
		return (0,0)
	cost_type = 0
	cost = 0
	for l in range(from_level+1, to_level+1):
		c = building.GetBuildCost(l)
		cost_type = c[0]
		cost += c[1]
	return (cost_type, cost)


all_buildings = [
"AirDefense",
"ArcherQueenAltar",
"ArcherTower",
"ArmyCamp",
"BarbarianKingAltar",
"Barracks",
"Cannon",
"ClanCastle",
"DarkBarracks",
"DarkElixirDrill",
"DarkElixirStorage",
"ElixirCollector",
"ElixirStorage",
"GoldMine",
"GoldStorage",
"HiddenTesla",
"InfernoTower",
"Laboratory",
"Mortar",
"SpellFactory",
"TownHall",
"Wall",
"WizardTower",
"XBow",
]

townhall_from_level = 7
townhall_to_level = 8 #所有建筑升满

time_need = 0
gold_need = 0
elixir_need = 0
dark_elixir_need = 0

factory = ObjectFactory()

for name in all_buildings:
	#print name
	building = factory.Create(name)
	
	number_new = building.GetMaxNumber(townhall_to_level)-building.GetMaxNumber(townhall_from_level)
	number_upgrade = building.GetMaxNumber(townhall_from_level)
	level_to = building.GetMaxLevel(townhall_to_level)
	level_from = building.GetMaxLevel(townhall_from_level)

	if number_new > 0:
		time_need += number_new*GetTimeNeed(building, 0, level_to)
		cost = GetCost(building, 0, level_to)
		if cost[0] == 0:
			gold_need += cost[1]
		elif cost[0] == 1:
			elixir_need += cost[1]
		elif cost[0] == 2:
			dark_elixir_need += cost[1]
	if number_upgrade > 0:
		time_need += number_upgrade*GetTimeNeed(building, level_from, level_to)
		cost = GetCost(building, level_from, level_to)
		if cost[0] == 0:
			gold_need += cost[1]
		elif cost[0] == 1:
			elixir_need += cost[1]
		elif cost[0] == 2:
			dark_elixir_need += cost[1]

	#print name, time_need

print "time_need: %f days" % (time_need/24.0/3600)
print "gold_need: %u" % gold_need
print "elixir_need: %u" % elixir_need 
print "dark_elixir_need: %u" % dark_elixir_need

